﻿using Ebusiness_UserService.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Ebusiness_UserService.Data.Config
{
    public class UserConfig : IEntityTypeConfiguration<User>
    {
        public void Configure(EntityTypeBuilder<User> builder)
        {
            builder.ToTable("T_User");
            builder.OwnsOne(x => x.phoneNumber, nb =>
            {
                nb.Property(x => x.Code).HasMaxLength(5).IsUnicode(false);
                nb.Property(x => x.Phone).HasMaxLength(20).IsUnicode(false);
            });
            //builder.Ignore(x => x.HasPassword); //忽略属性
            //builder.Property(x => x.AvatarUrl).HasColumnName("AvatarUrl_fild"); //列取别名
            //builder.Property(x => x.AvatarUrl).HasColumnType("varchar(200)"); //配置列数据类型
            //builder.Property(x => x.AvatarUrl).HasColumnType("varchar(200)").IsRequired();

            builder.Property("passwordHash").HasMaxLength(100).IsUnicode(false);
            builder.HasOne(x => x.userAccessFail).WithOne(d => d.User).HasForeignKey<UserAccessFail>(x => x.Userld).OnDelete(DeleteBehavior.Cascade);// 删除 Order 同时删除 Detail
        }
    }
}
